//index.js
//获取应用实例
const app = getApp()
import Http from '../../utils/http.js';
Page({
  data: {
    sqModel:false,
    imgUrls: []
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  //点击图片
  handleImgTap(e){
    const type = e.currentTarget.dataset.type;
    switch (type){
      case 'ROOM':
        wx.navigateTo({
          url: '../houseList/houseList'
        })
        break;
      case 'STRATEGY':
        wx.navigateTo({
          url: '../travelList/travelList'
        })
        break;
      case 'CAR':
        wx.navigateTo({
          url: '../carList/carList'
        })
        break;
      case 'MATERIAL':
        wx.navigateTo({
          url: '../shiwuList/shiwuList'
        })
        break;
    }
  },
  onLoad: function () {
    Http.Request('GET', '/api/customer/order/carouselPicture').then(res => {
      this.setData({
        imgUrls:res
      })
    })
    if (!wx.getStorageSync('userInfo')){
      this.setData({
        sqModel: true
      })
    }
  },
  onGotUserInfo(e) {
    this.setData({
      sqModel: false
    })
    if (!e.detail || !e.detail.userInfo) return;
    const userInfo = e.detail.userInfo;
    console.log(userInfo)
    const data = {
      custPortrait: userInfo.avatarUrl,
      username: userInfo.nickName
    }
    Http.Request('post', `/api/customer/uploadCustPortrait/v1`, data)
    app.globalData.userInfo = userInfo;
    wx.setStorageSync('userInfo', userInfo);
  },
  navigateClick(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  changeIndicatorDots(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  },
  onShareAppMessage(){
    app.globalFn.onShareAppMessage()
  }
  
})
